﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ADDUSER=APP.WS.AddUserClassService;
using ADDPERMI = APP.WS.AddPermissionClassService;
using ADDUSERPERMI = APP.WS.AddUserPermissionRelClassService;
using SHOWPERMI = APP.WS.GetAllPermissionService;
using SHOWUSER = APP.WS.GetAllUserService;
using ADDRECORDS = APP.WS.AddRecordClassService;
using ADDFACTS = APP.WS.AddFactsClassService;
using ADDRESULTS = APP.WS.AddResultsClassService;
using SHOWUSERUUID = APP.WS.GetUserUUIDClassService;
using GETOPNS = APP.WS.GetOperationClassService;
using GETRECORDSWHERE = APP.WS.GetRecordWhereClassService;
using System.IO;
using System.Runtime.Remoting.Messaging;
namespace APP
{
    public partial class WSForm : Form
    {
        static readonly string ExportAll = "导出所有";
        public WSForm()
        {
            InitializeComponent();
            bt_addUser.Enabled = Authorization.IsControlVisiable(bt_addUser.Parent, bt_addUser, "系统", null);
            bt_addPermission.Enabled = Authorization.IsControlVisiable(bt_addUser.Parent, bt_addUser, "系统", null);
            bt_addrel.Enabled = Authorization.IsControlVisiable(bt_addUser.Parent, bt_addUser, "系统", null);
            button1.Enabled = Authorization.IsControlVisiable(bt_addUser.Parent, bt_addUser, "系统", null);
            bt_loadBatch.Enabled = Authorization.IsControlVisiable(bt_addUser.Parent, bt_addUser, "系统", null);
            bt_exportBydanwei.Enabled = Authorization.IsControlVisiable(bt_addUser.Parent, bt_addUser, "系统", null);

            //bt_export_record.Enabled = Authorization.IsControlVisiable(bt_addUser.Parent, bt_addUser, "系统", null);
            foreach (string danwei in DanWeiManager.DanWeiList)
            {
                if(!cb_danwei.Items.Contains(danwei))
                    cb_danwei.Items.Add(danwei);
            }
            cb_danwei.Items.Add(ExportAll);
        }
        delegate void SetTextCallback(string text);
        private void SetText(string text)
        {
            // InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.rt_info.InvokeRequired)
            {
                SetTextCallback d = new SetTextCallback(SetText);
                this.Invoke(d, new object[] { text });
            }
            else
            {
                this.rt_info.Text += text;
            }
        }

        #region synchronize user
        /// <summary>
        /// 同步方式进行
        /// </summary>
        private void ExportUserInfo()
        {
            User[] _users = UserHelper.GetAllUser();
            ADDUSER.user[] _wwwUsers = null;
            if (_users != null && _users.Length > 0)
            {
                _wwwUsers = new ADDUSER.user[_users.Length];
                for (int i = 0; i < _users.Length; i++)
                {
                    _wwwUsers[i] = new ADDUSER.user();
                    _wwwUsers[i].id = CommonHelper.GenUUID();
                    _wwwUsers[i].loginName = _users[i].Name;
                    _wwwUsers[i].loginPassword = _users[i].Password;
                    _wwwUsers[i].userDesc = _users[i].SuoXie;
                    _wwwUsers[i].userName = _users[i].PingYing;
                    _wwwUsers[i].roleId = CommonHelper.GetWWWRoleName(_users[i].Roles[0]);
                    _wwwUsers[i].unitId = CommonHelper.GetWWWDanwei(_users[i].DanWei);
                }
                ADDUSER.AddUserClassService adduserservice = new ADDUSER.AddUserClassService();
                try
                {
                    adduserservice.AddUser(_wwwUsers);
                    rt_info.Text += "\n共导入" + _wwwUsers.Length.ToString() + "个用户！";
                }
                catch (Exception ex)
                {
                    rt_info.Text += ex.ToString();
                }
            }
        }

        private void bt_addUser_Click(object sender, EventArgs e)
        {
            User[] _users = UserHelper.GetAllUser();
            ADDUSER.user[] _wwwUsers = null;
            if(_users!=null && _users.Length>0)
            {
                _wwwUsers = new ADDUSER.user[_users.Length];
                for (int i=0;i<_users.Length;i++)
                {
                    _wwwUsers[i] = new ADDUSER.user();
                    _wwwUsers[i].id = CommonHelper.GenUUID();
                    _wwwUsers[i].loginName = _users[i].Name;
                    _wwwUsers[i].loginPassword = _users[i].Password;
                    _wwwUsers[i].userDesc =_users[i].SuoXie;
                    _wwwUsers[i].userName = _users[i].PingYing;
                    _wwwUsers[i].roleId = CommonHelper.GetWWWRoleName(_users[i].Roles[0]);
                    _wwwUsers[i].unitId = CommonHelper.GetWWWDanwei(_users[i].DanWei);
                }
                ADDUSER.AddUserClassService adduserservice = new ADDUSER.AddUserClassService();
                adduserservice.AddUserCompleted += new ADDUSER.AddUserCompletedEventHandler(delegate(object sender1, System.ComponentModel.AsyncCompletedEventArgs e1)
                    {
                        if (e1.Error != null)
                            rt_info.Text += e1.Error.ToString();
                        rt_info.Text += "\n共导入" + _wwwUsers.Length.ToString() + "个用户！";
                    });
                adduserservice.AddUserAsync(_wwwUsers);
            }
            
            //adduserservice.AddUserAsync()
        }
        #endregion


        #region synchro permission
        /// <summary>
        /// 同步方式
        /// </summary>
        private void ExportPermissions()
        {
            try
            {
                rt_info.Text += "\n正在清空权限表...";
                APP.WS.DeletePermissionClassService.DeletePermissionClassService deletePermission = new WS.DeletePermissionClassService.DeletePermissionClassService();
                deletePermission.DeleteAllPermission();
                rt_info.Text += "\n清空完毕。";

                List<ADDPERMI.permission> _PermissionList = new List<ADDPERMI.permission>();

                RootNode _rootAdmin = CommonHelper.GetAllLocalPermission("admin");
                if (_rootAdmin != null && _rootAdmin.ChildNodes != null && _rootAdmin.ChildNodes.Length > 0)
                {
                    foreach (Node n in _rootAdmin.ChildNodes)
                    {
                        AddPermissionNodeHelper(_PermissionList, n, 1, "0");
                    }
                }

                ADDPERMI.AddPermissionClassService addpermiss = new ADDPERMI.AddPermissionClassService();

                addpermiss.AddPermissions(_PermissionList.ToArray());
                rt_info.AppendText("\n添加权限成功！共："+_PermissionList.Count.ToString()+"条！");
            }
            catch (Exception ex)
            {
                rt_info.Text += ex.ToString();
            }
        }

        private void bt_addPermission_Click(object sender, EventArgs e)
        {
            try
            {
                rt_info.Text += "\n正在清空权限表...";
                APP.WS.DeletePermissionClassService.DeletePermissionClassService deletePermission = new WS.DeletePermissionClassService.DeletePermissionClassService();
                deletePermission.DeleteAllPermission();
                rt_info.Text += "\n清空完毕。";

                List<ADDPERMI.permission> _PermissionList = new List<ADDPERMI.permission>();

                RootNode _rootAdmin = CommonHelper.GetAllLocalPermission("admin");
                if (_rootAdmin != null && _rootAdmin.ChildNodes != null && _rootAdmin.ChildNodes.Length > 0)
                {
                    foreach (Node n in _rootAdmin.ChildNodes)
                    {
                        AddPermissionNodeHelper(_PermissionList, n, 1, "0");
                    }
                }

                ADDPERMI.AddPermissionClassService addpermiss = new ADDPERMI.AddPermissionClassService();
                addpermiss.AddPermissionsCompleted += new ADDPERMI.AddPermissionsCompletedEventHandler(delegate(object sender1, System.ComponentModel.AsyncCompletedEventArgs e1)
                    {
                        if (e1.Error != null)
                            rt_info.Text += e1.Error.ToString();
                        else
                            rt_info.AppendText("\n添加权限成功！");
                    });

                addpermiss.AddPermissionsAsync(_PermissionList.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        void AddPermissionNodeHelper(List<ADDPERMI.permission> list,Node node ,int level,string uplevelUUID)
        {
            if (node != null)
            {
                string realName = PaintTreeView<RootNode, Node>.GetRealName(PaintTreeView < RootNode, Node > .GetRidOfIndexPrefix(node.NodeName), level);
                string currentNodeUUID = CommonHelper.GenUUID();
                ADDPERMI.permission p = new ADDPERMI.permission();
                p.id = currentNodeUUID;
                p.perName = realName;
                p.perDesc = PaintTreeView<RootNode, Node>.GetRidOfIndexPrefix(node.NodeName);
                if (!string.IsNullOrEmpty(uplevelUUID))
                    p.perPid = uplevelUUID;

                p.url = "URL";
                p.versionSpecified = true;
                p.perTypeSpecified = true;
                p.perSortnoSpecified = true;
                p.perType = level - 1;
                p.version = 0;
                p.perSortno = 1;
                
                list.Add(p);

                if (node.ChildNodes != null && node.ChildNodes.Length > 0)
                {
                    foreach (Node cNode in node.ChildNodes)
                    {
                        AddPermissionNodeHelper(list, cNode, level + 1, currentNodeUUID);
                    }
                }
            }
        }
        #endregion


        #region synchro relations
        /// <summary>
        /// 同步方式
        /// </summary>
        private void ExportRelations()
        {
            try
            {
                rt_info.Text += "\n先清空关系表...";
                APP.WS.DeleteTableClassService.DeleteTableClassService deleterel = new WS.DeleteTableClassService.DeleteTableClassService();
                deleterel.DeleteTable("sys_userpermission_rel");
                rt_info.Text += "\n清空完毕！";


                SHOWUSER.GetAllUserService getusersService = new SHOWUSER.GetAllUserService();
                SHOWUSER.user[] _WWWUsers = getusersService.GetAllUsers();
                Dictionary<string, string> _userDic = new Dictionary<string, string>();
                foreach (SHOWUSER.user u in _WWWUsers)
                {
                    if (!_userDic.ContainsKey(u.loginName))
                        _userDic.Add(u.loginName, u.id);
                    else
                    {
                        System.Console.WriteLine("重复:" + u.loginName);
                    }
                }
                rt_info.Text += "加载用户==" + _WWWUsers.Length.ToString() + "个";

                SHOWPERMI.GetAllPermissionService getPerssionService = new SHOWPERMI.GetAllPermissionService();
                SHOWPERMI.permission[] _WWWpermissions = getPerssionService.GetAllPermissions();
                Dictionary<string, string> _permiDic = new Dictionary<string, string>();
                foreach (SHOWPERMI.permission p in _WWWpermissions)
                {
                    _permiDic.Add(p.perName + p.perPid, p.id);
                }
                rt_info.Text += "加载权限==" + _WWWpermissions.Length.ToString() + "个";

                //遍历用户
                ADDUSERPERMI.AddUserPermissionRelClassService addrel = new ADDUSERPERMI.AddUserPermissionRelClassService();
                List<ADDUSERPERMI.userPermissionRel> _relList = new List<ADDUSERPERMI.userPermissionRel>();


                RootNode[] _userRoots = CommonHelper.GetAllLocalPermission();
                if (_userRoots != null && _userRoots.Length > 0)
                {
                    foreach (RootNode _userRoot in _userRoots)
                    {
                        if (_userRoot != null && _userRoot.ChildNodes != null && _userRoot.ChildNodes.Length > 0)
                        {
                            //进来每个用户都要添加perid=0的记录
                            if (_userDic.ContainsKey(_userRoot.RootValue))
                            {
                                string uerUUID = _userDic[_userRoot.RootValue];
                                ADDUSERPERMI.userPermissionRel _reltemp = new ADDUSERPERMI.userPermissionRel();
                                _reltemp.id = CommonHelper.GenUUID();
                                _reltemp.permId = "0";
                                _reltemp.userId = uerUUID;
                                _relList.Add(_reltemp);

                                foreach (Node node in _userRoot.ChildNodes)
                                {
                                    AddRelHelper(_relList, uerUUID, node, _permiDic, "0", 1);
                                }
                            }
                            else
                            {
                                Console.WriteLine(_userRoot.RootValue);
                            }
                        }
                    }
                }


                if (_relList.Count > 0)
                {
                    addrel.AddUserPermissionRel(_relList.ToArray());
                    rt_info.Text += "导入关系共：" + _relList.Count.ToString() + "条！";
                }
            }
            catch (Exception ex)
            {
                rt_info.Text += ex.ToString();
            }
        }

        private void bt_addrel_Click(object sender, EventArgs e)
        {
            try
            {
                rt_info.Text += "\n先清空关系表...";
                APP.WS.DeleteTableClassService.DeleteTableClassService deleterel = new WS.DeleteTableClassService.DeleteTableClassService();
                deleterel.DeleteTable("sys_userpermission_rel");
                rt_info.Text += "\n清空完毕！";


                SHOWUSER.GetAllUserService getusersService = new SHOWUSER.GetAllUserService();
                SHOWUSER.user[] _WWWUsers = getusersService.GetAllUsers();
                Dictionary<string, string> _userDic = new Dictionary<string, string>();
                foreach (SHOWUSER.user u in _WWWUsers)
                {
                    _userDic.Add(u.loginName, u.id);
                }
                rt_info.Text += "加载用户==" + _WWWUsers.Length.ToString() + "个";

                SHOWPERMI.GetAllPermissionService getPerssionService = new SHOWPERMI.GetAllPermissionService();
                SHOWPERMI.permission[] _WWWpermissions = getPerssionService.GetAllPermissions();
                Dictionary<string, string> _permiDic = new Dictionary<string, string>();
                foreach (SHOWPERMI.permission p in _WWWpermissions)
                {
                    _permiDic.Add(p.perName + p.perPid, p.id);
                }
                rt_info.Text += "加载权限==" + _WWWpermissions.Length.ToString() + "个";

                //遍历用户
                ADDUSERPERMI.AddUserPermissionRelClassService addrel = new ADDUSERPERMI.AddUserPermissionRelClassService();
                List<ADDUSERPERMI.userPermissionRel> _relList = new List<ADDUSERPERMI.userPermissionRel>();


                    RootNode[] _userRoots = CommonHelper.GetAllLocalPermission();
                    if (_userRoots != null && _userRoots.Length > 0)
                    {
                        foreach (RootNode _userRoot in _userRoots)
                        {
                            if (_userRoot != null && _userRoot.ChildNodes != null && _userRoot.ChildNodes.Length > 0)
                            {
                                //进来每个用户都要添加perid=0的记录
                                if (_userDic.ContainsKey(_userRoot.RootValue))
                                {
                                    string uerUUID = _userDic[_userRoot.RootValue];
                                    ADDUSERPERMI.userPermissionRel _reltemp = new ADDUSERPERMI.userPermissionRel();
                                    _reltemp.id = CommonHelper.GenUUID();
                                    _reltemp.permId = "0";
                                    _reltemp.userId = uerUUID;
                                    _relList.Add(_reltemp);

                                    foreach (Node node in _userRoot.ChildNodes)
                                    {
                                        AddRelHelper(_relList, uerUUID, node, _permiDic, "0", 1);
                                    }
                                }
                                else
                                {
                                    Console.WriteLine(_userRoot.RootValue);
                                }
                            }
                        }
                    }
                

                if (_relList.Count > 0)
                {
                    addrel.AddUserPermissionRelCompleted += new ADDUSERPERMI.AddUserPermissionRelCompletedEventHandler(delegate(object sender1, System.ComponentModel.AsyncCompletedEventArgs e1)
                        {
                            if (e1.Error != null)
                                rt_info.Text += e1.Error.ToString();
                            else
                                rt_info.Text += "导入关系共：" + _relList.Count.ToString() + "条！";
                        });
                    addrel.AddUserPermissionRelAsync(_relList.ToArray());
                }
            }
            catch (Exception ex)
            {
                rt_info.Text += ex.ToString();
            }
        }

        void AddRelHelper(List<ADDUSERPERMI.userPermissionRel> relList, string UserUUID, Node node,Dictionary<string, string> permiDic,string ParentUUID,int level)
        {
            if (node != null)
            {
                ADDUSERPERMI.userPermissionRel rel = new ADDUSERPERMI.userPermissionRel();
                string realName = PaintTreeView<RootNode, Node>.GetRealName(PaintTreeView<RootNode, Node>.GetRidOfIndexPrefix(node.NodeName), level);
                rel.id = CommonHelper.GenUUID();
                rel.userId = UserUUID;
                if (permiDic.ContainsKey(realName + ParentUUID))
                {
                    rel.permId = permiDic[realName + ParentUUID];
                    relList.Add(rel);
                }

                if (node.ChildNodes != null && node.ChildNodes.Length > 0)
                {
                    foreach (Node cNode in node.ChildNodes)
                    {
                        AddRelHelper(relList, UserUUID, cNode, permiDic, rel.permId, level + 1);
                    }
                }
            }
        }
        #endregion

        private void bt_export_record_Click(object sender, EventArgs e)
        {
            TransferHoldForProveRecordToWWW();
            MessageBox.Show("导入网络版完成！");
        }

        /// <summary>
        /// Empty if not exists.
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        private string GetRecordPath(Record record)
        {
            string realPath = "";
            string picfoldername = record.InputUser + "- 图片" + @"\" + record.ID;

            if (record == null)
                return string.Empty;

            if (UserSession.LoginUser.Role == Roles.RoleFactorTeamManager || UserSession.LoginUser.Role == Roles.Admin)
            {
                string[] temp = RecordHelper.RecordDBPath.Split(new char[] { '\\' });
                string filename = temp[temp.Length - 1];
                realPath = RecordHelper.RecordDBPath.Replace(filename, "");
            }
            else
            {
                string[] temp = MainForm.currentDBPath.Split(new char[] { '\\' });
                string filename = temp[temp.Length - 1];
                realPath = MainForm.currentDBPath.Replace(filename, "");
            }
            string recordFolder = System.IO.Path.Combine(realPath, picfoldername);
            if (System.IO.Directory.Exists(recordFolder))
            {
                string[] directorys = System.IO.Directory.GetDirectories(recordFolder);
                if (directorys != null && directorys.Length > 0)
                {
                    return recordFolder;
                }
            }
            return string.Empty;
        }

        private void bt_import_Click(object sender, EventArgs e)
        {
            Record example =new Record();
            example.Status = RecordStatus.HoldForApprove;
            //example.InputUser = UserSession.LoginUser.PingYing;

            Record[] _holdforapproveRecords = RecordHelper.GetByExampleArray(example);
            if (_holdforapproveRecords != null && _holdforapproveRecords.Length > 0)
            {
                List<Record> _updateList = new List<Record>();

                foreach (Record record in _holdforapproveRecords)
                {
                    GETOPNS.record[] wwwRecords = null;
                    try
                    {
                        wwwRecords = new GETOPNS.GetOperationClassService().GetRecords(record.ID);
                    }
                    catch (System.Exception ex)
                    {
                        rt_info.Text += "\n" + ex.ToString();
                    }

                    if (wwwRecords != null && wwwRecords.Length > 0)
                    {
                        //if (record.Status == RecordStatus.Inputed)
                        //        wwwRecord.status = "0";
                        //    if (record.Status == RecordStatus.HoldForApprove)
                        //        wwwRecord.status = "1";
                        //    if (record.Status == RecordStatus.Approved)
                        //        wwwRecord.status = "4";
                        //    if (record.Status == RecordStatus.ReturnBack)
                        //        wwwRecord.status = "3";
                        //    if (record.Status == RecordStatus.Deleted)
                        //        wwwRecord.status = "2";

                        if (wwwRecords[0].status == "0")
                            record.Status = RecordStatus.Inputed;
                        if (wwwRecords[0].status == "1")
                            record.Status = RecordStatus.HoldForApprove;
                        if (wwwRecords[0].status == "2")
                            record.Status = RecordStatus.Deleted;
                        if (wwwRecords[0].status == "3")
                            record.Status = RecordStatus.ReturnBack;
                        if (wwwRecords[0].status == "4")
                            record.Status = RecordStatus.Approved;
                        if (!string.IsNullOrEmpty(wwwRecords[0].sendBackReaSon))
                        {
                            record.SendBackReason = wwwRecords[0].sendBackReaSon;
                        }
                        if(!string.IsNullOrEmpty(wwwRecords[0].approveBy))
                            record.ApproveBy = wwwRecords[0].approveBy;
                        //
                        if(wwwRecords[0].approveTime!=null)
                            record.ApproveTime = wwwRecords[0].approveTime;
                        _updateList.Add(record);
                    }
                }
                RecordHelper.UpdateRecords(_updateList);
                rt_info.Text += "\n成功同步：" + _updateList.Count.ToString() + "条记录！";

                MessageBox.Show("请点击 \"查询\" 按钮，刷新记录！");
            }
            rt_info.Text += "\n您没有记录需要同步！";
        }

        public delegate void ExportInfoHandler();
        private void ExportConfig()
        {
            ExportUserInfo();
            ExportPermissions();
            ExportRelations();
        }

        private void ExportCallBack(IAsyncResult asResult)
        {
            try
            {
                //do nothing but close invoke
                AsyncResult result = (AsyncResult)asResult;
                ExportInfoHandler dele = (ExportInfoHandler)result.AsyncDelegate;
                dele.EndInvoke(asResult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            ExportInfoHandler _exportinfo = new ExportInfoHandler(ExportConfig);
            //_exportinfo.BeginInvoke(ExportCallBack, null);
            _exportinfo.Invoke();
        }

        private void bt_loadBatch_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                rt_info.Text += "\n开始批量导入数据...";
                List<string> yapFiles = new List<string>();
                CommonHelper.GetYapsFromRootDirectory(yapFiles,folderBrowserDialog1.SelectedPath);
                rt_info.Text += "\n共"+" "+yapFiles.Count+" 个yap文件。";
                if (yapFiles != null && yapFiles.Count>0)
                {
                    foreach (string yapFile in yapFiles)
                    {
                        rt_info.Text += "\n" + "开始导入文件" + yapFile + "...";
                        //string loginUser = UserHelper.GetUserLoginNameByDbFilePath(yapFile);
                        //if (!string.IsNullOrEmpty(loginUser))
                        //{
                        //rt_info.Text += "\n当前导入用户：" + loginUser + " 的记录...";
                        RecordHelper.RefreshDBOfRecord(yapFile);
                        MainForm.IsMyDB = false;
                        TransferHoldForProveRecordToWWW();
                        //}
                        //else
                        //{
                        //    rt_info.Text += "\n错误！" + "文件：" + yapFile + " 用户:\"" + System.IO.Path.GetFileNameWithoutExtension(yapFile) + "\" 不存在！";
                        //}
                    }
                    rt_info.Text += "\n完成导入！";
                    //完成导入后切回自己的库。
                    string jiluPath = AppDomain.CurrentDomain.BaseDirectory + "记录\\";
                    string YapFileName = jiluPath + UserSession.LoginUser.PingYing + ".yap";
                    RecordHelper.RefreshDBOfRecord(YapFileName);
                    MainForm.currentDBPath = YapFileName;
                    MainForm.IsMyDB = true;

                    MessageBox.Show("导入完成！");
                }
                else
                {
                    rt_info.Text += "\n请检查这个路径：" + folderBrowserDialog1.SelectedPath+" 这个路径没有符合要求的数据文件！";
                }
            }
        }

        /// <summary>
        /// 直接通过RecordHelper来取得Record，然后通过筛选已提交记录完成导入。
        /// 在Oracle数据库中做了重复提交判断，这里没有做。
        /// </summary>
        private void TransferHoldForProveRecordToWWW()
        {
            try
            {
                Record[] LocalRecords = RecordHelper.GetAll();
                if (LocalRecords != null && LocalRecords.Length > 0)
                {

                    GETOPNS.GetOperationClassService getOP = new GETOPNS.GetOperationClassService();
                    List<ADDFACTS.fact> _WWWFacts = new List<ADDFACTS.fact>();
                    List<ADDRECORDS.record> _WWWRecords = new List<ADDRECORDS.record>();
                    List<ADDRESULTS.recordResult> _WWWresults = new List<ADDRESULTS.recordResult>();
                    List<APP.WS.InsertFileDBClassService.psrFile> _fileDb = new List<APP.WS.InsertFileDBClassService.psrFile>();
                    SHOWUSERUUID.GetUserUUIDClassService userUUIDService = new SHOWUSERUUID.GetUserUUIDClassService();
                    string loginUser = null; string suoxie = null;
                    //只上传提交审批的记录
                    foreach (Record record in LocalRecords)
                    {
                        if (record.Status == RecordStatus.HoldForApprove || record.Status==RecordStatus.Approved)
                        {
                            try
                            {
                                #region 获取用户信息
                                suoxie = UserHelper.GetUserSuoxieByRecord(record);
                                if (suoxie == null)
                                    continue;
                                User _u = new User();
                                _u.SuoXie = suoxie;
                                User[] _us = UserHelper.GetByExample(_u);
                                if (_us != null && _us.Length > 0)
                                {
                                    loginUser = _us[0].Name;
                                }
                                else
                                    continue;

                                string userUUID = userUUIDService.GetUserUUID(loginUser);
                                rt_info.Text += "\n====================================\n";
                                rt_info.Text += "开始!记录:" + record.ID;

                                rt_info.Text += "。录入用户：" + loginUser;//UserSession.LoginUser.Name;

                                rt_info.Text += "\n用户UUID为:" + userUUID;
                                #endregion
                                #region 导入记录
                                ADDRECORDS.record wwwRecord = new ADDRECORDS.record();

                                //判断是否是在库中存在
                                GETOPNS.record[] wwwgetRecord = getOP.GetRecords(record.ID);
                                //如果已存在，而且推进到了已审批或者已删除则不导入。会覆盖的。
                                if (wwwgetRecord != null && wwwgetRecord.Length > 0)
                                {
                                    if ((wwwgetRecord[0].status == "2" || wwwgetRecord[0].status == "4") && wwwgetRecord[0].createUser != null)
                                        continue;
                                    else
                                        wwwRecord.id = wwwgetRecord[0].id;
                                }
                                else
                                {
                                    wwwRecord.id = CommonHelper.GenUUID();
                                }
                                wwwRecord.count = record.Count;//审查的次数
                                wwwRecord.createUser = userUUID;
                                wwwRecord.createDate = record.InputTime;
                                wwwRecord.createDateSpecified = true;

                                if (record.InputTime != null)
                                {
                                    wwwRecord.inputTimeSpecified = true;
                                    wwwRecord.inputTime = record.InputTime;
                                }
                                wwwRecord.inputUSer = loginUser;//UserSession.LoginUser.Name;
                                wwwRecord.inputUSerSuoXie = record.InputUserSuoXie;
                                wwwRecord.recordNo = record.ID;
                                wwwRecord.sendBackReaSon = record.SendBackReason;

                                if (record.Status == RecordStatus.Inputed)
                                    wwwRecord.status = "0";
                                if (record.Status == RecordStatus.HoldForApprove)
                                    wwwRecord.status = "1";
                                if (record.Status == RecordStatus.Approved)
                                    wwwRecord.status = "4";
                                if (record.Status == RecordStatus.ReturnBack)
                                    wwwRecord.status = "3";
                                if (record.Status == RecordStatus.Deleted)
                                    wwwRecord.status = "2";

                                wwwRecord.commentS = record.Comments;
                                wwwRecord.danwei = record.DanWei;
                                wwwRecord.equiptment = record.Equipment;
                                wwwRecord.topic = record.Topic;
                                wwwRecord.topicDesc = record.RecordDesciption;
                                wwwRecord.facility = FacilityName.GetFacilityNameByNO(record.Facility);
                                wwwRecord.upLoadedTimeSpecified = true;
                                wwwRecord.upLoadedTime = DateTime.Now;

                                wwwRecord.yaoSubianhao = YaoSuManager.GetElementNameByNO(record.YaoSuBianHao);
                                if (record.ZhuangTiBianHao != null && record.ZhuangTiBianHao != string.Empty)
                                {
                                    wwwRecord.zhuangtibianhao = ZhuanTiManager.GetSubjectNameByNO(record.ZhuangTiBianHao);
                                }

                                wwwRecord.updateUser = loginUser;//UserSession.LoginUser.Name;

                                wwwRecord.approveBy = record.ApproveBy;
                                if (record.ApproveTime != null)
                                {
                                    wwwRecord.approveTimeSpecified = true;
                                    wwwRecord.approveTime = record.ApproveTime;
                                }

                                wwwRecord.isActivityInspectionSpecified = true;
                                wwwRecord.isCommunicationSpecified = true;
                                wwwRecord.isDocumentRevisionSpecified = true;
                                wwwRecord.isWalkDownSpecified = true;
                                wwwRecord.isComplianceSpecified = true;

                                wwwRecord.isActivityInspection = record.IsActivityInspection;
                                wwwRecord.isCommunication = record.IsCommunication;
                                wwwRecord.isCompliance = record.IsCompliance;
                                wwwRecord.isWalkDown = record.IsWalkDown;
                                wwwRecord.isDocumentRevision = record.IsDocumentRevision;
                                wwwRecord.recordDeSciption = record.RecordDesciption;
                                _WWWRecords.Add(wwwRecord);
                                #endregion
                                #region 导入结论
                                //导入结论
                                Dictionary<int, int> _resultAsso = new Dictionary<int, int>();
                                if (record.Results != null && record.Results.Count > 0)
                                {
                                    foreach (RecordResult r in record.Results)
                                    {
                                        ADDRESULTS.recordResult wwwResult = new ADDRESULTS.recordResult();
                                        wwwResult.id = CommonHelper.GenUUID();

                                        wwwResult.isFHSpecified = true;
                                        wwwResult.isPCSpecified = true;
                                        wwwResult.isFH = r.IsFH;
                                        wwwResult.isPC = r.IsPC;

                                        //是否是更新，如果是，不更新record的uuid否则找不到记录
                                        wwwResult.recordID = wwwRecord.id;

                                        wwwResult.content = r.Content;
                                        wwwResult.factNos = r.AgainstFacts;

                                        wwwResult.resultNoSpecified = true;
                                        string rawresultid = r.ID.Replace("result", "");
                                        wwwResult.resultNo = int.Parse(rawresultid) + 1;

                                        string[] factNos = r.AgainstFacts.Split(new char[] { ',' });
                                        foreach (string s in factNos)
                                        {
                                            int temp = int.Parse(s);
                                            _resultAsso.Add(temp, wwwResult.resultNo);
                                        }

                                        wwwResult.createDateSpecified = true;
                                        wwwResult.createDate = record.InputTime;
                                        wwwResult.createUser = record.InputUser;
                                        wwwResult.recordNo = wwwRecord.recordNo;
                                        _WWWresults.Add(wwwResult);
                                    }
                                }
                                #endregion
                                #region 导入fact
                                //导入fact
                                if (record.Facts != null && record.Facts.Count > 0)
                                {
                                    foreach (Fact f in record.Facts)
                                    {
                                        ADDFACTS.fact wwwFact = new ADDFACTS.fact();
                                        wwwFact.id = CommonHelper.GenUUID();
                                        wwwFact.content = f.Content;
                                        wwwFact.factNo = int.Parse(f.ID) + 1;
                                        wwwFact.factNoSpecified = true;

                                        //wwwFact.isFhSpecified = true;
                                        //wwwFact.isPcSpecified = true;
                                        //wwwFact.isFh = f.IsFH;
                                        //wwwFact.isPc = f.IsPC;
                                        wwwFact.recordID = wwwRecord.id;


                                        wwwFact.createDateSpecified = true;
                                        wwwFact.createDate = record.InputTime;
                                        wwwFact.createUser = wwwRecord.inputUSer;
                                        wwwFact.imagesPath = " ";
                                        wwwFact.associateResultSpecified = true;
                                        wwwFact.associateResult = _resultAsso[wwwFact.factNo];//f.AssociateResult;
                                        wwwFact.recordNo = wwwRecord.recordNo;
                                        _WWWFacts.Add(wwwFact);

                                        #region 导入图片
                                        //上传图片
                                        APP.WS.UpLoadFileClassService.UpLoadFileClassService ufc = new APP.WS.UpLoadFileClassService.UpLoadFileClassService();
                                        string recordPath = GetRecordPath(record);
                                        if (recordPath != string.Empty && System.IO.Directory.Exists(recordPath))
                                        {
                                            string dirStr = recordPath + @"\事实" + wwwFact.factNo.ToString();
                                            //查看是否存在事实路径
                                            if (Directory.Exists(dirStr))
                                            {
                                                rt_info.Text += "\n正在导入记录:" + record.ID + " 的图片....";
                                                string[] filepaths = System.IO.Directory.GetFiles(dirStr);
                                                if (filepaths != null && filepaths.Length > 0)
                                                {
                                                    //遍历文件
                                                    foreach (string filepath in filepaths)
                                                    {
                                                        if (File.Exists(filepath))
                                                        {
                                                            FileInfo fi = new FileInfo(filepath);
                                                            long len = fi.Length;
                                                            FileStream fs = new FileStream(filepath, FileMode.Open);
                                                            byte[] buffer = new byte[len];
                                                            fs.Read(buffer, 0, (int)len);
                                                            fs.Close();
                                                            string WWWPathPrefix = record.InputUser + "-图片" + @"\" + record.ID + @"\事实" + wwwFact.factNo.ToString();
                                                            //ufc.UpLoadAsync(buffer, WWWPathPrefix, fi.Name, fi.Name);

                                                            IAsyncResult uploadResult = ufc.BeginUpLoad(buffer, WWWPathPrefix, fi.Name, new AsyncCallback(delegate(IAsyncResult ar)
                                                            {
                                                                //rt_info.Text += "\n成功导入: " + dirStr + " 下图片:" + (string)ar.AsyncState;
                                                                //SetText("\n成功导入: " + dirStr + " 下图片:" + (string)ar.AsyncState);
                                                            }), fi.Name);
                                                            uploadResult.AsyncWaitHandle.WaitOne();
                                                            try
                                                            {
                                                                ufc.EndUpLoad(uploadResult);
                                                                rt_info.Text += "\n成功导入: " + dirStr + " 下图片:" + fi.Name;
                                                            }
                                                            catch (System.Exception ex)
                                                            {
                                                                rt_info.Text += "\nUpLoadPic发生异常.记录ID：" + record.ID + "\n" + ex.StackTrace;
                                                                //throw ex;
                                                            }
                                                            //更新文件数据库
                                                            APP.WS.InsertFileDBClassService.psrFile psrfile = new APP.WS.InsertFileDBClassService.psrFile();
                                                            psrfile.id = CommonHelper.GenUUID();
                                                            psrfile.reId = wwwFact.id;
                                                            psrfile.createDate = DateTime.Now;
                                                            psrfile.createDateSpecified = true;
                                                            psrfile.createUser = record.InputUser;
                                                            psrfile.fileName = fi.Name;
                                                            psrfile.filePath = WWWPathPrefix;
                                                            _fileDb.Add(psrfile);
                                                        }
                                                    }

                                                }
                                            }
                                        }

                                        #endregion
                                    }
                                }
                                #endregion
                            }
                            catch (Exception ex)
                            {
                                rt_info.Text += "记录："+record.ID+" 导入发生错误，信息如下：";
                                rt_info.Text += ex.ToString();
                            }
                        }
                    }

                    if (_WWWRecords.Count == 0)
                    {
                        rt_info.Text += "\n您没有记录需要上传！";
                        return;
                    }
                    //导入记录
                    ADDRECORDS.AddRecordClassService addrecord = new ADDRECORDS.AddRecordClassService();
                    IAsyncResult arRecord = addrecord.BeginAddRecords(_WWWRecords.ToArray(), new AsyncCallback(delegate(IAsyncResult ar)
                        {
                            //SetText("\n成功导入:" + _WWWRecords.Count.ToString() + "条记录!");
                        }), null);
                    arRecord.AsyncWaitHandle.WaitOne();
                    try
                    {
                        addrecord.EndAddRecords(arRecord);
                        rt_info.Text += "\n成功导入:" + _WWWRecords.Count.ToString() + "条记录!";
                    }
                    catch (System.Exception ex)
                    {
                        rt_info.Text += "\n"+loginUser+"的记录AddRecord发生异常.\n" + ex.ToString();
                        //throw ex;
                    }

                    //导入时事
                    ADDFACTS.AddFactsClassService addFacsService = new ADDFACTS.AddFactsClassService();
                    IAsyncResult arFact = addFacsService.BeginAddFacts(_WWWFacts.ToArray(), new AsyncCallback(delegate(IAsyncResult ar)
                        {
                            //rt_info.Text += "\n成功导入:" + _WWWFacts.Count.ToString() + "条事实!";
                        }), null);
                    arFact.AsyncWaitHandle.WaitOne();
                    try
                    {
                        addFacsService.EndAddFacts(arFact);
                        rt_info.Text += "\n成功导入:" + _WWWFacts.Count.ToString() + "条事实!";
                    }
                    catch (System.Exception ex)
                    {
                        rt_info.Text += "\n" + loginUser + "的记录AddFact发生异常.\n" + ex.ToString();
                        //throw ex;
                    }
                    

                    //导入结论
                    ADDRESULTS.AddResultsClassService addresultservice = new ADDRESULTS.AddResultsClassService();
                    IAsyncResult arResult = addresultservice.BeginAddResults(_WWWresults.ToArray(), new AsyncCallback(delegate(IAsyncResult ar)
                    {
                        //rt_info.Text += "\n成功导入:" + _WWWresults.Count.ToString() + "条结论!";
                    }), null);
                    arResult.AsyncWaitHandle.WaitOne();
                   try
                   {
                       addresultservice.EndAddResults(arResult);
                       rt_info.Text += "\n成功导入:" + _WWWresults.Count.ToString() + "条结论!";
                   }
                   catch (System.Exception ex)
                   {
                       rt_info.Text += "\n" + loginUser + "的记录AddResult发生异常.\n" + ex.ToString();
                       //throw ex;
                   }

                    //更新图片数据库
                    APP.WS.InsertFileDBClassService.InsertFileDBClassService updateFileDb = new APP.WS.InsertFileDBClassService.InsertFileDBClassService();
                    IAsyncResult arFile = updateFileDb.BeginInsertFileDB(_fileDb.ToArray(),
                        new AsyncCallback(delegate(IAsyncResult ar)
                        {
                            //rt_info.Text += "\n成功导入:" + _fileDb.Count.ToString() + "个图片！";
                            //_fileDb.Clear();
                        }), null);
                    arFile.AsyncWaitHandle.WaitOne();
                    try
                    {
                        updateFileDb.EndInsertFileDB(arFile);
                        rt_info.Text += "\n成功导入:" + _fileDb.Count.ToString() + "个图片！";
                        _fileDb.Clear();
                    }
                    catch (System.Exception ex)
                    {
                        rt_info.Text += "\n" + loginUser + "的记录AddFile发生异常.\n" + ex.StackTrace;
                        //throw ex;
                    }
                    rt_info.Text += "\n用户："+loginUser+" 的记录完成导入！";
                    rt_info.Text += "\n====================================";
                }
            }
            catch (System.Exception ex)
            {
                rt_info.Text += ex.ToString();
            }
        }

        private void bt_exportBydanwei_Click(object sender, EventArgs e)
        {
            if (cb_danwei.SelectedItem!=null)
            {
                string cbDanwei = cb_danwei.SelectedItem.ToString();
                TransferWWWDanweiToYap(cbDanwei);
                MessageBox.Show("导出完成！");
            }
        }
        private void TransferWWWDanweiToYap(string danwei)
        {
            GETRECORDSWHERE.record[] _retRecords = null;

            rt_info.Text += "\n开始导出单位:" + danwei + "...\n";
            //select * from psr_record where DANWEI='运行公司'
            string whereSql="";
            if (danwei.Equals(ExportAll))
                whereSql = "danwei is not null or danwei is null";
            else
                whereSql = " DANWEI=\'" + danwei + "\' or RECORDNO like \'%" + danwei + "%\'";
            GETRECORDSWHERE.GetRecordWhereClassService service = new GETRECORDSWHERE.GetRecordWhereClassService();
            IAsyncResult arRecord = service.BeginGetRecordWhere(whereSql, null, null);
            arRecord.AsyncWaitHandle.WaitOne();
            try
            {
                _retRecords = service.EndGetRecordWhere(arRecord);
                if (_retRecords != null && _retRecords.Length > 0)
                {
                    rt_info.Text += "\n共需要导出：" + _retRecords.Length.ToString() + "条记录\n";
                    List<Record> _updateList = new List<Record>();
                    GETOPNS.GetOperationClassService getOptService = new GETOPNS.GetOperationClassService();
                    //用于去重复，如果存在一样的FactNo，则不入库。
                    List<int> _factNos = new List<int>();
                    List<int> _resultNos = new List<int>();
                    foreach (GETRECORDSWHERE.record wwwRecord in _retRecords)
                    {
                        try
                        {
                            #region 准备record
                            Record recordLocal = new Record();

                            recordLocal.ApproveBy = wwwRecord.approveBy;//中文

                            if (wwwRecord.approveTimeSpecified)
                                recordLocal.ApproveTime = wwwRecord.approveTime;

                            recordLocal.Comments = wwwRecord.commentS;
                            recordLocal.Count = wwwRecord.count;
                            recordLocal.DanWei = wwwRecord.danwei;//中文
                            recordLocal.Equipment = wwwRecord.equiptment;
                            recordLocal.Facility = FacilityName.GetFacilityNO(wwwRecord.facility);//映射，中文名称

                            if (wwwRecord.haveAttachedSpecified)
                                recordLocal.HaveAttached = wwwRecord.haveAttached;
                            if (wwwRecord.haveqiangxiangSpecified)
                                recordLocal.HaveQiangxiang = wwwRecord.haveqiangxiang;
                            if (wwwRecord.haveruoxiangSpecified)
                                recordLocal.HaveRuoXiang = wwwRecord.haveruoxiang;

                            recordLocal.ID = wwwRecord.recordNo;
                            if (recordLocal.ID == "QN10241工程公司wanzy001")
                                Console.WriteLine();
                            if (wwwRecord.inputTimeSpecified)
                                recordLocal.InputTime = wwwRecord.inputTime;

                            recordLocal.InputUser = UserHelper.GetUser(wwwRecord.inputUSer).PingYing;//映射

                            recordLocal.InputUserSuoXie = wwwRecord.inputUSerSuoXie;

                            if (wwwRecord.isActivityInspectionSpecified)
                                recordLocal.IsActivityInspection = wwwRecord.isActivityInspection;
                            else
                                recordLocal.IsActivityInspection = false;

                            if (wwwRecord.isCommunicationSpecified)
                                recordLocal.IsCommunication = wwwRecord.isCommunication;
                            else
                                recordLocal.IsCommunication = false;

                            if (wwwRecord.isComplianceSpecified)
                                recordLocal.IsCompliance = wwwRecord.isCompliance;
                            else
                                recordLocal.IsCompliance = false;

                            if (wwwRecord.isDocumentRevisionSpecified)
                                recordLocal.IsDocumentRevision = wwwRecord.isDocumentRevision;
                            else
                                recordLocal.IsDocumentRevision = false;

                            if (wwwRecord.isWalkDownSpecified)
                                recordLocal.IsWalkDown = wwwRecord.isWalkDown;
                            else
                                recordLocal.IsWalkDown = false;

                            recordLocal.SendBackReason = wwwRecord.sendBackReaSon;

                            if (wwwRecord.status == "0")
                                recordLocal.Status = RecordStatus.Inputed;
                            if (wwwRecord.status == "1")
                                recordLocal.Status = RecordStatus.HoldForApprove;
                            if (wwwRecord.status == "2")
                                recordLocal.Status = RecordStatus.Deleted;
                            if (wwwRecord.status == "3")
                                recordLocal.Status = RecordStatus.ReturnBack;
                            if (wwwRecord.status == "4")
                                recordLocal.Status = RecordStatus.Approved;

                            recordLocal.Topic = wwwRecord.topic;
                            recordLocal.RecordDesciption = wwwRecord.topicDesc;

                            if (wwwRecord.iSUpDatedSpecified)
                                recordLocal.IsUpDated = wwwRecord.iSUpDated;
                            if (wwwRecord.iSUpLoadSpecified)
                                recordLocal.IsUpLoad = wwwRecord.iSUpLoad;

                            if (wwwRecord.updatedTimeSpecified)
                                recordLocal.UpDatedTime = wwwRecord.updatedTime;

                            if (wwwRecord.iSUpLoadSpecified)
                                recordLocal.UpLoadedTime = wwwRecord.upLoadedTime;

                            recordLocal.YaoSuBianHao = YaoSuManager.GetYaoSuBianHao(wwwRecord.yaoSubianhao);
                            recordLocal.ZhuangTiBianHao = ZhuanTiManager.GetSubjectNO(wwwRecord.zhuangtibianhao);


                            #endregion

                            string recordNo = wwwRecord.recordNo;
                            //if (recordNo == "QN10126成都一院yjh001")
                            //    Console.WriteLine();
                            #region 准备fact

                            GETOPNS.fact[] _wwwfacts = getOptService.GetFacts(recordNo);

                            if (_wwwfacts != null && _wwwfacts.Length > 0)
                            {
                                List<Fact> _localFacts = new List<Fact>();
                                _factNos.Clear();
                                foreach (GETOPNS.fact wwwfact in _wwwfacts)
                                {
                                    //if (wwwfact.recordNo == "Q120445运行公司cy001")
                                    //    Console.WriteLine(wwwfact.recordNo);

                                    Fact factLocal = new Fact();
                                    //factLocal.AssociateResult = 0;// wwwfact.associateResult;
                                    factLocal.Content = wwwfact.content;

                                    int wwwfactNo = wwwfact.factNo - 1;
                                    if (_factNos.Contains(wwwfactNo))
                                        continue;
                                    else
                                        _factNos.Add(wwwfactNo);

                                    if (wwwfactNo > 9 && wwwfactNo < 100)
                                        factLocal.ID = "0" + wwwfactNo.ToString();
                                    if (wwwfactNo <= 9)
                                        factLocal.ID = "00" + wwwfactNo.ToString();
                                    if (wwwfactNo >= 100)
                                        factLocal.ID = wwwfactNo.ToString();

                                    factLocal.RecordNo = wwwfact.recordNo;
                                    _localFacts.Add(factLocal);
                                }
                                recordLocal.Facts = _localFacts;
                            }
                            else
                            {
                                rt_info.Text += "\n错误！记录：" + recordLocal.ID + "没有事实！\n";
                                continue;
                            }
                            #endregion

                            #region 准备result
                            GETOPNS.recordResult[] _wwwResults = getOptService.GetResults(recordNo);
                            if (_wwwResults != null && _wwwResults.Length > 0)
                            {
                                List<RecordResult> _localResults = new List<RecordResult>();
                                _resultNos.Clear();
                                foreach (GETOPNS.recordResult wwwResult in _wwwResults)
                                {
                                    RecordResult localResult = new RecordResult();
                                    localResult.AgainstFacts = wwwResult.factNos;
                                    localResult.Content = wwwResult.content;

                                    int ReulstNo = wwwResult.resultNo - 1;
                                    if (_resultNos.Contains(ReulstNo))
                                        continue;
                                    else
                                        _resultNos.Add(ReulstNo);

                                    localResult.ID = "result" + ReulstNo.ToString();
                                    if (wwwResult.isFHSpecified)
                                        localResult.IsFH = wwwResult.isFH;
                                    if (wwwResult.isPCSpecified)
                                        localResult.IsPC = wwwResult.isPC;
                                    localResult.RecordNo = wwwResult.recordNo;

                                    _localResults.Add(localResult);
                                }
                                recordLocal.Results = _localResults;
                            }
                            else
                            {
                                rt_info.Text += "\n错误！记录：" + recordLocal.ID + "没有结论！\n";
                                continue;
                            }
                            #endregion
                            _updateList.Add(recordLocal);
                        }
                        catch (Exception ex)
                        {
                            rt_info.Text += "\n出错的记录为：" + wwwRecord.recordNo + "\n" + ex.ToString();
                        }
                    }
                    string jiluPath = AppDomain.CurrentDomain.BaseDirectory + "记录\\";
                    string YapFileName = "";
                    ////先清空
                    //YapFileName = jiluPath + UserSession.LoginUser.PingYing + ".yap";
                    //RecordHelper.RefreshDBOfRecord(YapFileName);
                    //MainForm.currentDBPath = YapFileName;
                    //打开
                    YapFileName = jiluPath + "导出-" + danwei + ".yap";
                    if (System.IO.File.Exists(YapFileName))
                        System.IO.File.Delete(YapFileName);

                    RecordHelper.RefreshDBOfRecordNoCheckFileExits(YapFileName);
                    RecordHelper.UpdateRecords(_updateList.ToArray());
                    rt_info.Text += "\n完成" + _updateList.Count.ToString() + "条记录的导入\n";

                    //恢复
                    YapFileName = jiluPath + UserSession.LoginUser.PingYing + ".yap";
                    RecordHelper.RefreshDBOfRecord(YapFileName);
                    MainForm.currentDBPath = YapFileName;
                }
            }
            catch (System.Exception ex)
            {
                rt_info.Text += "\nGetRecordByDanwei Error(生成失败):" + ex.StackTrace + "\n";
            }
        }
    }
}
